package com.example.hang.msgqueue;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class MainNavActivity extends AppCompatActivity {

    private GridView gvContainer;

    private String[] itemName = {"UI消息","线程消息"};
    private Class<?>[] destList = {HandlerUiMsgActivity.class,MsgHandlerActivity.class};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_nav);


        gvContainer = (GridView)findViewById(R.id.gvContainer);

        List<HashMap<String,Object>> data = new ArrayList<HashMap<String, Object>>();
        for(int i = 0; i < itemName.length; i++){
            HashMap<String,Object> map = new HashMap<String,Object>();
            map.put("btnItem",itemName[i]);
            data.add(map);
        }

        SimpleAdapter simpleAdapter = new SimpleAdapter(MainNavActivity.this,data,
                R.layout.grid_item,
                new String[]{"btnItem"},
                new int[]{R.id.btnItem});
        gvContainer.setAdapter(simpleAdapter);

        //点击 GridView 的单元格
        gvContainer.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(MainNavActivity.this,destList[position]);
                startActivity(intent);
            }
        });
    }
}
